package db.core;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import db.DBManager;
import db.QueryHelper;
import entity.Category;

public class CategoryDBHelper {
	
	public CategoryDBHelper() {
		
	}
	
	public Category[] getCategoryAll() {
		QueryHelper.query_cache(beanClass, cache_region, key, sql, params);
	}
	public void delCategory(int[] arr) {
		int i = 0;
		try {
			Connection conn = DBManager.getConnection();
			while (i < arr.length) {
				PreparedStatement pstmt = conn.prepareStatement("DEL FROM goodcategory where cid=?");
				pstmt.setInt(1, arr[i]);
				pstmt.executeUpdate();
			}
			DBManager.closeConnection();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	
	public void addCategory(Category c) throws SQLException {
		Connection conn = DBManager.getConnection();
		PreparedStatement pstmt = conn.prepareStatement("INSERT INTO " +
				"goodcategory(cname, fatherid, description, picpath) VALUES(?, ?, ?, ?)");
		
		pstmt.setString(1, c.getCname());
		pstmt.setInt(2, c.getFatherid());
		pstmt.setString(3, c.getDetail());
		pstmt.setString(4, c.getPicpath());
		
		pstmt.executeUpdate();
	}
	
	public void getCategory(int fatherid) {
		
	}
}
